home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-04-12 | 46.6 KB | 1,849 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
- { The above is the official MacApp PasMat Style statement.
- What you don’t use pasmat to make all your source code
- conform to your company’s (or personal) standard for source
- code style? }
-
- {Copyright © 1986-1988 by Apple Computer, Inc. All rights reserved.}
- {Copyright © 1989 by Software Architects, Inc. All rights reserved.}
- {Portions Copyright © 1988 MacTutor All rights reserved.}
-
- {[f-]}
- (*
- This is a very small sample application which uses concepts and program fragments
- presented in the February 1988 MacTutor Plot Article.
-
- By looking at this program you may be able to gain a better understanding of how to
- cast a conventional program into the MacApp “Application Framework” or (Class structure
- depending upon whose jargon you wish to use).
-
- In the tradition of MacApp it defines the basic three Class (object) overrides:
-
- TPlotApplication.DoMakeDocument -- Launches the appropriate type of Document
- object
- TPlotDoc.DoMakeViews -- Launches the appropriate type of View
- and window objects
- TPlotDialog.Draw -- Calls it sub components to draw the
- contents of a view
- TPlotView -- To actually plot the thing
- TSolveView -- To draw the solution text box
-
- In addition it defines commands unique to the plot program.
- See the text of the accompaning article for detials.
-
- *)
- {[f+]}
-
- UNIT UPlot;
-
- INTERFACE
- USES
- { • MacApp - this includes all of the things necessary from the MacApp Library }
- UMacApp,
-
- { • Building Blocks }
- UDialog, UPrinting, UExtendedText,
-
- { • Implementation Use }
- SANE, ToolUtils, Fonts, Resources, Script, PickerIntf, Packages;
-
- CONST
-
- kSignature = 'Plot'; { Application signature}
- kFileType = 'PICT'; { File-type code used for document files
- created by this application}
- kPlotDialog = 1010;
-
- { MacApp uses a very useful technique for seperating menu item numbering from
- what you want done by chosing a menu item. See MacApp manual pggs xxx-xx
- for full details. Work is done in MacApp with commands. Each command is
- usuallly assigned a unique number. For example Save is 30 and SaveAs is 32.
- Numbers belwo 1200 are reserved for MacApp.
-
- In this Application we have chosen a command numbering scheme that makes life
- easy:
- Application Commands= 1400
- Font styles = 2000
- Font sizes = 2100
- Font just = 2200
- Font fonts = 2300
- Hierarchical Menus = 2400
- Plot colors = 2500
- }
-
- cPlotIt = 1401; { the command to cause a plot to happen }
-
- { Command numbers for typestyle attributes }
- cPlainText = 2001;
- cBold = 2002;
- cItalic = 2003;
- cUnderline = 2004;
- cOutline = 2005;
- cShadow = 2006;
- cCondense = 2007;
- cExtend = 2008;
-
- { Command numbers for font-size commands }
- cSizeChange = 2100;
- cSizeBase = 2100;
- cSizeMin = 2109;
- cSizeMax = 2124;
-
- { 2101-2197 reserved for font sizes 1-97 pts. }
- cSizeGrow = 2198;
- cSizeShrink = 2199;
-
- { Command numbers to cover other stylistic changes }
- cJustChange = 2200;
- cJustLeft = 2201; { Justification commands }
- cJustCenter = 2202;
- cJustRight = 2203;
-
- cFontChange = 2300;
-
- { Command numbers for the hierarchial menu }
- cStyle = 2401;
- cSize = 2402;
- cFont = 2403;
- cColor = 2404;
-
- { Command numbers for changing colors }
- cColorChange = 2500;
- cColorText = 2501;
- cColorBackground = 2502;
- cColorGraph = 2503;
- cColorAxis = 2504;
-
- { Constant for amount to relative size text selection }
- kRelSizeAmount = 4;
-
- { Constants for the prompts string list }
- kPromptsRsrcID = 1001;
- kColTextPrompt = 1;
- kColBackPrompt = 2;
- kColGraphPrompt = 3;
- kColAxisPrompt = 4;
-
- { Menu numbers }
- mFont = 10;
-
- kHierDisplayedMBar = 131; { Menus displayed on hier. menu system }
- kNonHierDisplayedMBar = 128; { Menus displayed on non-hier. system }
-
- kHierMenuOffset = 1000; { Offset added to non-hier menu cmds to get }
- kViewRsrcID = 1005; { 'view' resource for default values }
-
- kBlackColor = 33; { for a Black forground }
-
- { PICT comments for our plot and text box }
-
- {selected MacDraw comments}
- picDwgBeg = 130;
- picDwgEnd = 131;
- picGrpBeg = 140;
- picGrpEnd = 141;
- TextBegin = 150;
- TextEnd = 151;
- StringBegin = 151;
- StringEnd = 153;
- TextCenter = 154;
-
- {postscript comments}
- SetLineWidth = 182;
- PostScriptBegin = 190;
- TextIsPostscript = 194;
- PostScriptEnd = 191;
-
- { The size of a MacDraw Header }
- kHeaderSize = 512;
-
- TYPE
-
- QuadraticType = (NotSolved,RealRoots,SingleSolution,ComplexRoot);
-
- (* remove this ???
- PlotDocDiskInfo = RECORD
- tempA : INTEGER;
- tempB : INTEGER;
- tempC : INTEGER;
- END;
- *)
-
- PlotSpecs = RECORD {specifications of text display}
- theTextFont: Str255;
- theFontNum: INTEGER;
- theTextFace: Style;
- theTextSize: INTEGER;
- theJustification: INTEGER; { text justification }
- theTextColor: RGBColor; { text label color }
- theGraphColor: RGBColor; { The color to draw the graph }
- theAxisColor: RGBColor; { and our axes }
- theBackColor: RGBColor; { Window's background color }
- END;
- PlotSpecsPtr = ^PlotSpecs;
- PlotSpecsHdl = ^PlotSpecsPtr;
-
-
- { Object Definitions }
- {---------------------------------------------------}
- TPlotApplication = OBJECT (TApplication)
-
- PROCEDURE TPlotApplication.IPlotApplication(itsMainFileType: OSType);
- { Initializes the application and globals. }
-
- FUNCTION TPlotApplication.DoMakeDocument(itsCmdNumber: cmdNumber): TDocument;
- OVERRIDE;
- { Launches a TPlotDocument }
-
- (*
- FUNCTION TPlotApplication.MakeViewForAlienClipboard: TView; OVERRIDE;
- *)
-
- PROCEDURE TPlotApplication.IdentifySoftware; OVERRIDE;
- PROCEDURE TPlotApplication.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;fieldType: INTEGER)); OVERRIDE;
-
- END; { TPlotApplication }
-
- {---------------------------------------------------}
- TPlotDoc = OBJECT (TDocument)
-
- fPlotDialog : TPlotDialog;
- fPlotSpecs : PlotSpecs;
- fOldPlot : PicHandle;
-
- faParam : Real;
- fbParam : Real;
- fcParam : Real;
- { the coefficients to our quadratic equation }
-
- fstepParam : Real;
- fxParam : INTEGER;
- fyParam : INTEGER;
- { plot display parameters }
-
- f1stRoot : Real;
- f2ndRoot : Real;
- { the solutions to our quadratic }
-
- fRootType : QuadraticType;
-
- PROCEDURE TPlotDoc.IPlotDocument;
- { setup for the document to hold the plot }
-
- PROCEDURE TPlotDoc.DoInitialState; OVERRIDE;
- { For new doc or revert setup an initial state }
-
- FUNCTION TPlotDoc.DoMakePStyleCmd(itsStyle:PlotSpecsPtr; itsCmdNumber:CmdNumber): TPStyleCmd;
- { Generate a command to change the Look of a plot }
-
- PROCEDURE TPlotDoc.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
- { create all the views needed for the document }
-
- PROCEDURE TPlotDoc.DoNeedDiskSpace(VAR dataForkBytes,
- rsrcForkBytes: LONGINT); OVERRIDE;
- { calculater how much disk space this document will need }
-
- PROCEDURE TPlotDoc.DoRead(aRefNum: INTEGER; rsrcExists,
- forPrinting: BOOLEAN); OVERRIDE;
- { read the data for this document }
-
- PROCEDURE TPlotDoc.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
- { write the data for this document }
-
- FUNCTION TPlotDoc.DoMenuCommand(aCmdNumber: cmdNumber): TCommand; OVERRIDE;
- { given a Menu choice handle it or pass it on }
-
- PROCEDURE TPlotDoc.DoSetupMenus; OVERRIDE;
- { setup the menus for the document }
-
- PROCEDURE TPlotDoc.SolveQuadratic;
- { given the parameters of our document calculate a solution }
-
- PROCEDURE TPlotDoc.ChangeBackColor(newColor: RGBColor);
-
- {$IFC qDebug}
- PROCEDURE TPlotDoc.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- {$ENDC}
-
- END; { TPlotDoc }
-
-
- TPlotView = OBJECT (TView)
-
- fPlotDoc : TPlotDoc;
-
- PROCEDURE TPlotView.AddToPict(picRect:Rect);
- { Add to the pict we will draw on the screen or printed page }
-
- PROCEDURE TPlotView.GetQDFrame(VAR frameRect:Rect);
- { A convenience routine }
-
- PROCEDURE TPlotView.Resize(width, height: VCoordinate; invalidate: BOOLEAN); OVERRIDE
- { The design says the plot fills the window, therefore when we are
- resized we must invalidate ourselves}
- END;
-
- TSolutionView = OBJECT (TView)
-
- fPlotDoc : TPlotDoc;
- fSolveRect : Rect;
-
- PROCEDURE TSolutionView.AddToPict(picRect:Rect);
- { Add to the pict we will draw on the screen or printed page }
- END;
-
-
- TPlotDialog = OBJECT (TDialogView)
-
- fPlotSize : VPoint;
- fPlotView : TPlotView;
- fSolutionView : TSolutionView;
- fPlotDoc : TPlotDoc;
- fPlotPICT : PicHandle;
-
- FUNCTION TPlotDialog.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
- VAR info: EventInfo): TCommand; OVERRIDE;
-
- FUNCTION TPlotDialog.DoMenuCommand(aCmdNumber: CmdNumber):TCommand; OVERRIDE;
-
- PROCEDURE TPlotDialog.DismissDialog(dismisser: IDType;
- flashDismisser: BOOLEAN); OVERRIDE;
-
- PROCEDURE TPlotDialog.Draw(area: Rect); OVERRIDE;
-
- PROCEDURE TPlotDialog.EachSubView(PROCEDURE DoToSubView(theSubView: TView)); OVERRIDE
-
- PROCEDURE TPlotDialog.PlotNDrawPICT;
-
- PROCEDURE TPlotDialog.GetPlotValues;
-
- PROCEDURE TPlotDialog.DoSetupMenus; OVERRIDE;
-
- END;
-
- TPStyleCmd = OBJECT (TCommand)
- fPlotDialog : TPlotDialog;
- fOldPlotSpecs : PlotSpecs;
- fNewPlotSpecs : PlotSpecs;
-
- PROCEDURE TPStyleCmd.IPStyleCmd(itsPlotDialog:TPlotDialog; itsNewStyle:PlotSpecsPtr; itsCmdNumber: CmdNumber);
-
- { Initialize the command; if unsuccessful,
- signalled by Failure mechanism }
-
- PROCEDURE TPStyleCmd.DoIt; OVERRIDE;
- PROCEDURE TPStyleCmd.RedoIt; OVERRIDE;
- PROCEDURE TPStyleCmd.UndoIt; OVERRIDE;
- {
- PROCEDURE TCommand.Commit; OVERRIDE;
- }
- END;
-
- VAR
-
- gDefaultSpecs: PlotSpecs;
- gMenuOfs: INTEGER; { a Menu Management Global }
- gPromptString: Str255; { a Convenience for fetching
- strings from a resource }
-
- IMPLEMENTATION
- { I M P L E M E N T A T I O N }
- {---------------------------------------------------}
- {$S ARes}
-
- FUNCTION GetPrompt(index: INTEGER): StringPtr;
-
- BEGIN
- GetIndString(gPromptString, kPromptsRsrcID, index);
- GetPrompt := @gPromptString;
- END;
-
-
- FUNCTION Real2Str(aReal: Real; theDigits: INTEGER): Str255;
- VAR aStr : DecStr;
- form : DecForm;
- BEGIN
- form.style := FixedDecimal;
- form.digits := theDigits;
- Num2Str(form,aReal,aStr);
-
- Real2Str := aStr;
- END;
-
-
- {$IFC qDebug}
- {$IFC qTrace} {$D+} {$ENDC}
-
- { In the final version of MacApp 2.0 there will some kind of
- support for REAL numbers in text entry fields, for now
- we use Calvins Cock’s code from the January ’89 Frameworks }
-
- PROCEDURE MyFieldToString(theData: Ptr;
- fieldType: integer;
- VAR theString: str255);
-
- CONST
- DecPrec = 2; { Change this if you want more decimal precision }
-
- TYPE
- TAlias = RECORD
- CASE integer OF
- bReal, bSingle:
- (asReal : Real);
- bDouble:
- (asDouble : Double);
- bExtended:
- (asExtended : Extended);
- END;
-
- VAR
- alias : ^TAlias;
- aDecForm : DecForm;
- x : Extended;
- NumStr : DecStr;
-
- BEGIN
- alias := Pointer(theData);
- WITH alias^ DO
- CASE fieldType OF
- bReal, bSingle:
- BEGIN
- aDecForm.style := FixedDecimal;
- aDecForm.digits := DecPrec;
- x := asReal;
- Num2Str(aDecForm, x, NumStr);
- theString := str255(NumStr);
- END;
- bDouble:
- BEGIN
- aDecForm.style := FixedDecimal;
- aDecForm.digits := DecPrec;
- x := asDouble;
- Num2Str(aDecForm, x, NumStr);
- theString := str255(NumStr);
- END;
- bExtended:
- BEGIN
- aDecForm.style := FixedDecimal;
- aDecForm.digits := DecPrec;
- x := asExtended;
- Num2Str(aDecForm, x, NumStr);
- theString := str255(NumStr);
- END;
- OTHERWISE StdFieldToString(theData, fieldType, theString);
- END;
- END;
-
- {$IFC qTrace} {$D++} {$ENDC}
- {$ENDC qDebug}
-
- {---------------------------------------------------}
- {$S AReadFile}
-
- PROCEDURE ReadBytes(theRefNum: INTEGER; size: LONGINT; buffer: Ptr);
- { Utility for reading data from a file }
-
- BEGIN
- FailOSErr(FSRead(theRefNum, size, buffer));
- END;
-
-
- {---------------------------------------------------}
- {$S AWriteFile}
-
- PROCEDURE WriteBytes(theRefNum: INTEGER; size: LONGINT; buffer: Ptr);
- { Utility for writing data to a file. }
-
- BEGIN
- FailOSErr(FSWrite(theRefNum, size, buffer));
- END;
-
- {---------------------------------------------------}
- {$S AInit}
-
- PROCEDURE TPlotApplication.IPlotApplication(itsMainFileType: OSType);
- VAR
- fontName: Str255;
- aTEView: TTEView;
-
- BEGIN
-
- { qNeedsHierarchialMenus is a MacApp compile time flag you can
- set which will require the use of Heirarchical Menus }
-
- {$IFC NOT qNeedsHierarchialMenus}
- IF NOT gConfiguration.hasHierarchicalMenus THEN
- BEGIN
- gMBarDisplayed := kNonHierDisplayedMBar;
- gMenuOfs := 0;
- END
- ELSE
- {$ENDC}
- BEGIN
- gMBarDisplayed := kHierDisplayedMBar;
- gMenuOfs := kHierMenuOffset;
- END;
-
- IApplication(itsMainFileType);
-
- { Do not setup the menus if we were started up with the
- request to print }
- IF NOT gFinderPrinting THEN
- BEGIN
- AddResMenu(GetMHandle(mFont), 'FONT');
-
- SetStyle(cBold, [bold]);
- SetStyle(cUnderline, [underline]);
- SetStyle(cItalic, [italic]);
- SetStyle(cOutline, [outline]);
- SetStyle(cShadow, [shadow]);
- SetStyle(cCondense, [condense]);
- SetStyle(cExtend, [extend]);
- END;
-
-
- { We have the Viewedit tool at our disposal, so why not use it
- to create a useful resource to get our initial values from
- instead of hard-wiring the defaults. The technique here is to
- define a TTEView resource and use all those great fields that
- you can setup with viewEdit as the defaults, then trash the TTEView
- once all the work is done. }
-
- aTEView := TTEView(DoCreateViews(NIL, NIL, kViewRsrcID, gZeroVPt));
- FailNIL(aTEView);
-
- GetFontName(aTEView.fTextStyle.tsFont, fontName);
- WITH gDefaultSpecs, aTEView DO { Set up initial text specs }
- BEGIN
- theTextFont := fontName;
- theTextFace := fTextStyle.tsFace;
- theTextSize := fTextStyle.tsSize;
- theTextColor := fTextStyle.tsColor;
- theJustification := fJustification;
- theBackColor := gRGBWhite;
- END;
- aTEView.Free;
-
- { Until MacApp 2.0 debug and ViewTemplates support REALs this
- is our work around from Calvin Cock’s January ’89 MapApp
- Frameworks article. }
- gFieldToStrRtn := @MyFieldToString;
-
- END;
-
-
- {---------------------------------------------------}
- {$IFC qDebug}
- {$S ADebug}
-
- PROCEDURE TPlotApplication.IdentifySoftware;
-
- BEGIN
- WriteLn('Plot Source date: 31 Jan 89; Compiled: ', COMPDATE, ' @ ', COMPTIME);
- INHERITED IdentifySoftware;
- END;
-
-
-
- PROCEDURE TPlotApplication.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- BEGIN
- WITH gDefaultSpecs DO
- BEGIN
- DoToField(' Font', @theTextFont, bFontName);
- DoToField(' Face', @theTextFace, bStyle);
- DoToField(' Size', @theTextSize, bInteger);
- END;
- END;
- {$ENDC}
-
-
- {************************************************************************}
- { T P l o t D o c u m e n t }
- {************************************************************************}
-
- {---------------------------------------------------}
- {$S AOpen}
-
- PROCEDURE TPlotDoc.IPlotDocument;
-
- VAR
- aRect: Rect;
-
- BEGIN
- IDocument(kFileType, kSignature, kUsesDataFork, NOT kUsesRsrcFork, NOT kDataOpen,
- NOT kRsrcOpen);
-
- fOldPlot := NIL;
- END;
-
- {------------------------------------------------------------------------------}
- {$S AOpen}
-
- FUNCTION TPlotApplication.DoMakeDocument(itsCmdNumber: cmdNumber): TDocument;
-
- VAR
- aPlotDocument: TPlotDoc;
- dimensions: Rect;
-
- BEGIN
- { Allocate and initialize the document}
- NEW(aPlotDocument);
- FailNIL(aPlotDocument);
- aPlotDocument.IPlotDocument;
- DoMakeDocument := aPlotDocument;
- END;
-
- {------------------------------------------------------------------------------}
- {$S AOpen}
-
- PROCEDURE TPlotDoc.DoInitialState; OVERRIDE;
-
- BEGIN
- { when reverting to an old copy of a document we need to reset to some
- reasonable values }
-
- fPlotSpecs := gDefaultSpecs;
- fOldPlot := NIL;
- END;
-
- {---------------------------------------------------}
- FUNCTION TPlotDoc.DoMakePStyleCmd(itsStyle:PlotSpecsPtr; itsCmdNumber:CmdNumber): TPStyleCmd ;
- VAR
- aPStyleCmd: TPStyleCmd;
- aPlotDialog: TPlotDialog;
-
- BEGIN
- New(aPStyleCmd);
- FailNIL(aPStyleCmd);
- aPlotDialog := fPlotDialog;
- aPStyleCmd.IPStyleCmd(aPlotDialog, itsStyle, itsCmdNumber);
- DoMakePStyleCmd := aPStyleCmd;
- END;
-
-
- {---------------------------------------------------}
- {$S AOpen}
-
- PROCEDURE TPlotDoc.DoMakeViews(forPrinting: BOOLEAN);
-
- VAR
- aWindow: TWindow;
- aPlotDialog: TPlotDialog;
- aPlotView: TPlotView;
- aTEView: TTEView;
- aSolutionView: TSolutionView;
- aCluster: TCluster;
- aPrintHandler: TStdPrintHandler;
- anExtendedText: TExtendedText;
- aRect: Rect;
-
- BEGIN
- { We want to dynamically call these in exisitance. Do a New()
- call for each object type, so the linker doesn't strip them out. }
- IF gCreateWithTemplates THEN
- BEGIN
- New(aPlotDialog);
- New(aPlotView);
- New(aTEView);
- New(aSolutionView);
- New(aCluster);
- New(anExtendedText);
- END;
-
- { we will now ceate and connect up all the view and document variables }
-
- aWindow := NewTemplateWindow(kPlotDialog, SELF);
- { bring our plot window into exisitance }
-
- aPlotDialog := TPlotDialog(aWindow.FindSubView('DLOG'));
- FailNIL(aPlotDialog);
- { find the dialog portions and make certian we have it }
-
- fPlotDialog := aPlotDialog;
- { save this away for late when we need to easily find the dialog }
-
- aPlotDialog.fPlotDoc := SELF;
- { and of course we need to cross refer so tell the plotdialog who its doc is }
-
- IF (fOldPlot <> NIL) | (GetHandleSize(Handle(fOldPlot)) > 0 ) THEN
- aPlotDialog.fPlotPICT := fOldPlot
- { If the document has an old plot PICT display it }
- ELSE
- aPlotDialog.GetPlotValues;
- { Use the values from the resource to generate the first plot }
-
- { Find the PlotView and make some connections to our PlotDocument }
- aPlotView := TPlotView(aWindow.FindSubView('plot'));
- FailNIL(aPlotView);
- aPlotView.fPlotDoc := SELF;
- aPlotDialog.fPlotView := aPlotView;
- aPlotDialog.fPlotPICT := NIL;
- aPlotDialog.fPlotSize := aPlotView.fSize;
-
- { Find the SolutionView and make some connections to our PlotDocument }
- aSolutionView := TSolutionView(aWindow.FindSubView('qslv'));
- FailNIL(aSolutionView);
- aSolutionView.fPlotDoc := SELF;
- aPlotDialog.fSolutionView := aSolutionView;
-
- { while we are at it, retrieve the rectangle size we will use to display in }
- SetRect(aRect,0,0,aSolutionView.fSize.h,aSolutionView.fSize.v);
- aSolutionView.fSolveRect := aRect;
-
- { we want to limit the minimum size this window can be so…
- use the size of our clusters to determine the minimum}
- aCluster:= TCluster(aWindow.FindSubView('Ccof'));
- aWindow.fResizeLimits.top := aCluster.fSize.v * 2;
- aWindow.fResizeLimits.left := aCluster.fSize.h * 3;
- aCluster:= TCluster(aWindow.FindSubView('Cdsp'));
- aWindow.fResizeLimits.top := aWindow.fResizeLimits.top + aCluster.fSize.v;
-
- NEW(aPrintHandler);
- FailNIL(aPrintHandler);
- aPrintHandler.IStdPrintHandler(SELF, { its document }
- aPlotDialog, { its view }
- FALSE, { does not have square dots }
- TRUE, { horzontal page size is fixed }
- FALSE); { vertical page size is variable (could be
- set to true on non-style TE systems) }
- aPrintHandler.fMinimalMargins := FALSE;
-
- END;
-
- {---------------------------------------------------}
- {$S ASelCommand}
-
- FUNCTION TPlotDoc.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
-
- VAR
- aName: Str255;
- menu: INTEGER;
- item: INTEGER;
- newStyle: PlotSpecs;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoSizeChange(base: CmdNumber);
-
- BEGIN
- newStyle.theTextSize := aCmdNumber - base;
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cSizeChange);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoRelSizeChange(amount: INTEGER);
-
- BEGIN
- WITH newStyle DO
- theTextSize := theTextSize + amount;
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cSizeChange);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoFontChange;
-
- BEGIN
- GetItem(GetMHandle(menu), item, newStyle.theTextFont);
- GetFNum(aName, newStyle.theFontNum);
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cFontChange);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoColTextChange;
-
- VAR
- aColor: RGBColor;
-
- BEGIN
- aColor := fPlotSpecs.theTextColor;
- IF GetColor(Point($00400040), GetPrompt(kColTextPrompt)^, aColor, newStyle.theTextColor) THEN
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cColorText);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoColGraphChange;
-
- VAR
- aColor: RGBColor;
-
- BEGIN
- aColor := fPlotSpecs.theGraphColor;
- IF GetColor(Point($00400040), GetPrompt(kColGraphPrompt)^, aColor, newStyle.theGraphColor) THEN
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cColorGraph);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoColAxisChange;
-
- VAR
- aColor: RGBColor;
-
- BEGIN
- aColor := fPlotSpecs.theAxisColor;
- IF GetColor(Point($00400040), GetPrompt(kColAxisPrompt)^, aColor, newStyle.theAxisColor) THEN
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cColorAxis);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoColBackChange;
-
- VAR
- aColor: RGBColor;
-
- BEGIN
- aColor := fPlotSpecs.theBackColor;
- IF GetColor(Point($00400040), GetPrompt(kColBackPrompt)^, aColor, newStyle.theBackColor) THEN
- BEGIN
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cColorBackGround);
- END;
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoJustChange;
-
- VAR
- newJust: INTEGER;
- BEGIN
- CASE aCmdNumber OF
- cJustLeft:
- newJust := teJustLeft;
- cJustCenter:
- newJust := teJustCenter;
- cJustRight:
- newJust := teJustRight;
- END;
- newStyle.theJustification := newJust;
- DoMenuCommand := DoMakePStyleCmd(@newStyle, aCmdNumber);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoPlainChange;
-
- BEGIN
- newStyle.theTextFace := [];
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cStyleChange);
- END;
-
- {--------------------------------------------------------------}
-
- PROCEDURE DoStyleChange;
- VAR
- newFace : Style;
-
- BEGIN
- WITH newStyle DO
- BEGIN
- CASE aCmdNumber OF
- cBold:
- newFace := [bold];
- cItalic:
- newFace := [italic];
- cUnderline:
- newFace := [underline];
- cOutline:
- newFace := [outline];
- cShadow:
- newFace := [shadow];
- cCondense:
- newFace := [condense];
- cExtend:
- newFace := [extend];
- END;
- IF newFace * theTextFace = newFace THEN
- theTextFace := theTextFace - newFace
- ELSE
- theTextFace := theTextFace + newFace;
- END;
- DoMenuCommand := DoMakePStyleCmd(@newStyle, cStyleChange);
- END;
-
-
- {--------------------------------------------------------------}
-
- BEGIN { DoMenuCommand }
- DoMenuCommand := gNoChanges;
-
- newStyle := fPlotSPecs;
-
- CmdToMenuItem(aCmdNumber, menu, item);
-
- IF menu = mFont THEN
- DoFontChange
- ELSE
- CASE aCmdNumber OF
- cSizeMin..cSizeMax:
- DoSizeChange(cSizeBase);
-
- cSizeGrow:
- DoRelSizeChange(kRelSizeAmount);
-
- cSizeShrink:
- DoRelSizeChange( - kRelSizeAmount);
-
- cJustLeft..cJustRight:
- DoJustChange;
-
- cPlainText:
- DoPlainChange;
-
- cBold..cExtend:
- DoStyleChange;
-
- cColorText:
- DoColTextChange;
-
- cColorGraph:
- DoColGraphChange;
-
- cColorAxis:
- DoColAxisChange;
-
- cColorBackground:
- DoColBackChange;
-
- OTHERWISE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END;
- END;
-
-
- {---------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TPlotDoc.DoSetupMenus; OVERRIDE;
-
- VAR
- hasColor: BOOLEAN;
- hasStyle: BOOLEAN;
- checkPlain: BOOLEAN;
- checkSize: BOOLEAN;
- checkFont: BOOLEAN;
- specChange: BOOLEAN;
- just: INTEGER;
- item: INTEGER;
- fnt: INTEGER;
- c: INTEGER;
- aMode: INTEGER;
- aFace: Style;
- aMenuHandle: MenuHandle;
- aName: Str255;
- aStyle: TextStyle;
- theFont: INTEGER;
- aStr255: Str255;
-
- BEGIN
- INHERITED DoSetupMenus;
-
- hasColor := gConfiguration.hasColorQD;
- hasStyle := gConfiguration.hasStyleTextEdit;
-
- aStr255 := fPlotSpecs.theTextFont;
- GetFNum(aStr255, aStyle.tsFont);
- WITH aStyle, fPlotSpecs DO
- BEGIN
- tsFace := theTextFace;
- tsSize := theTextSize;
- tsColor := theTextColor;
- END;
- checkPlain := aStyle.tsFace = [];
- checkFont := TRUE;
-
- aMenuHandle := GetMHandle(mFont);
-
- GetFontName(aStyle.tsFont, aName); { Get real font number in case tsFont is }
- GetFNum(aName, theFont); { …the system or application font. }
- FOR item := 1 TO CountMItems(aMenuHandle) DO
- BEGIN
- { There can be more than 31 menu entries with scrolling menus, but trying to enable
- an item with number > 31 is bad news. If the menu itself is enabled (which it
- will be in MacApp if any of the first 31 items is enabled), then the extras
- will always be enabled. }
- IF item <= 31 THEN
- EnableItem(aMenuHandle, item);
- IF checkFont THEN
- BEGIN
- GetItem(aMenuHandle, item, aName);
- GetFNum(aName, fnt);
- CheckItem(aMenuHandle, item, fnt = theFont);
- END;
- END;
-
- just := fPlotSpecs.theJustification; { Enable justification related menu items }
- EnableCheck(cJustLeft, TRUE, (just = teJustLeft));
- EnableCheck(cJustCenter, TRUE, (just = teJustCenter));
- EnableCheck(cJustRight, TRUE, (just = teJustRight));
-
- {$IFC NOT qNeedsHierarchialMenus}
- IF gConfiguration.hasHierarchicalMenus THEN
- {$ENDC}
- BEGIN
- Enable(cStyle, TRUE); { Enable sub-menus }
- Enable(cSize, TRUE);
- Enable(cFont, TRUE);
- Enable(cColor, hasColor);
- END;
-
- aFace := aStyle.tsFace;
- EnableCheck(cPlainText, TRUE, checkPlain); { Enable normal Style menu items }
- EnableCheck(cBold, TRUE, bold IN aFace);
- EnableCheck(cItalic, TRUE, italic IN aFace);
- EnableCheck(cUnderline, TRUE, underline IN aFace);
- EnableCheck(cOutline, TRUE, outline IN aFace);
- EnableCheck(cShadow, TRUE, shadow IN aFace);
- EnableCheck(cCondense, TRUE, condense IN aFace);
- EnableCheck(cExtend, TRUE, extend IN aFace);
-
- FOR c := cSizeMin TO cSizeMax DO
- BEGIN
- IF hasStyle THEN
- checkSize := FALSE
- ELSE
- checkSize := (c - cSizeBase) = aStyle.tsSize;
- EnableCheck(c, TRUE, checkSize);
-
- IF ((NOT hasStyle) | { If the record isn't styled, or }
- RealFont(aStyle.tsFont,c-cSizeBase)) { the size is a real one }
- THEN aFace := [outline] { …then we outline it }
- ELSE
- aFace := [];
- SetStyle(c, aFace);
- END;
-
- Enable(cSizeGrow, TRUE);
- Enable(cSizeShrink, TRUE);
-
- Enable(cColorText, hasColor);
- Enable(cColorBackground, hasColor);
- Enable(cColorGraph, hasColor);
- Enable(cColorAxis, hasColor);
-
- END;
-
- {---------------------------------------------------}
- {$S AWriteFile}
-
- PROCEDURE TPlotDoc.DoNeedDiskSpace(VAR dataForkBytes, rsrcForkBytes: LONGINT);
-
- VAR
- r: Rect;
-
- BEGIN
-
- { In other MacApp Samples we would normally get the Print record
- space requirements by doing:
-
- INHERITED DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
-
- BUT seeing as we are trying to imitate a MacDraw File we will just do
- our size calculation }
-
- dataForkBytes := kHeaderSize { for std MacDraw Header }
- + GetHandleSize(Handle(fPlotDialog.fPlotPICT));
-
- { For now we will write only the PICT Handle in the future we
- might want to write the PlotSpecs and other parameters to the
- resource fork of the file }
- rsrcForkBytes := 0;
-
- END;
-
- {---------------------------------------------------}
- {$S AReadFile}
-
- PROCEDURE TPlotDoc.DoRead(aRefNum: INTEGER; rsrcExists, forPrinting: BOOLEAN);
-
- VAR
- fi: FailInfo;
- aPICTSize: LONGINT;
- aPICTHandle:Handle;
-
- PROCEDURE SkipDocHeaderInfo;
-
- BEGIN
- { skip the dummy header }
- FailOSErr(SetFPos(aRefNum,fsFromStart,kHeaderSize));
- END;
-
- PROCEDURE HdlReadFailure(error: OSErr; message: LONGINT);
-
- BEGIN
- { We ran into trouble reading the data for now do nothing}
- END;
-
- BEGIN
- CatchFailures(fi, HdlReadFailure);
-
- { Normally, we would ask our ancestors to read in their data by:
- INHERITED DoRead(aRefNum, rsrcExists, forPrinting);
- but we are imitating a MacDraw Doc and have to behave like one}
-
- SkipDocHeaderInfo;
-
- IF fOldPlot <> NIL THEN
- DisposHandle(Handle(fOldPlot));
-
- FailOSErr(GetEOF(aRefNum,aPICTSize));
- aPICTSize := aPICTSize - kHeaderSize;
- aPICTHandle := NewHandle(aPICTSize);
-
- HLock(aPICTHandle);
- ReadBytes(aRefNum, aPICTSize, aPICTHandle^);
- HUnLock(aPICTHandle);
-
- fOldPlot := PicHandle(aPICTHandle);
-
- Success(fi);
- END;
-
- {---------------------------------------------------}
- {$S AWriteFile}
-
- PROCEDURE TPlotDoc.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN);
-
- PROCEDURE WriteHeaderInfo;
-
- VAR
- aPtr: Ptr;
-
- BEGIN
- aPtr := NewPtrClear(kHeaderSize);
- FailNil(aPtr);
- WriteBytes(aRefNum, kHeaderSize, aPtr);
- DisposPtr(aPtr);
- END;
-
- PROCEDURE WritePlotInfo;
- VAR
- aPICTHandle : Handle;
- aPICTSize : LONGINT;
- BEGIN
- aPICTHandle := Handle(fPlotDialog.fPlotPICT);
- aPICTSize := GetHandleSize(aPICTHandle);
-
- HLock(aPICTHandle);
- WriteBytes(aRefNum, aPICTSize, aPICTHandle^);
- HUnLock(aPICTHandle);
- END;
-
-
- BEGIN
- WriteHeaderInfo;
- WritePlotInfo
- END;
-
- {---------------------------------------------------}
- {$S ARes}
- PROCEDURE TPlotDoc.SolveQuadratic;
- VAR
- a,b,c,check : real;
-
- FUNCTION PositiveCalc (a, b, check : real) : real;
- BEGIN
- PositiveCalc := (-b + sqrt(check)) / (2 * a);
- END;
-
- FUNCTION NegativeCalc (a, b, check : real) : real;
- BEGIN
- NegativeCalc := (-b - sqrt(check)) / (2 * a);
- END;
-
- BEGIN
- a := faParam;
- b := fbParam;
- c := fcParam;
-
- check := (b * b) - (4 * a * c);
-
- IF check = 0 THEN { we have a double root (same place twice) }
- BEGIN
- fRootType := SingleSolution;
- f1stRoot := PositiveCalc(a, b, check);
- f2ndRoot := f1stRoot;
- END
-
- ELSE IF check > 0 THEN { we have a pair of “real” x axis crossings }
- BEGIN
- fRootType := RealRoots;
- f1stRoot := PositiveCalc(a, b, check);
- f2ndRoot := NegativeCalc(a, b, check);
- END
-
- ELSE IF check < 0 THEN { the roots are represented by a complex number }
- BEGIN
- fRootType := ComplexRoot;
- check := -check;
- f1stRoot := PositiveCalc(a, b, check);
- f2ndRoot := NegativeCalc(a, b, check);
- END;
- END;
-
- {---------------------------------------------------}
- {$S ANonRes}
-
- PROCEDURE TPlotDoc.ChangeBackColor(newColor: RGBColor);
-
- VAR
- oldPort: GrafPtr;
- itsWindow: TWindow;
-
- BEGIN
- itsWindow := TView(fPlotDialog).GetWindow;
- IF itsWindow <> NIL THEN
- BEGIN
- GetPort(oldPort);
- SetPort(itsWindow.fWMgrWindow);
- RGBBackColor(newColor);
- itsWindow.ForceRedraw;
- SetPort(oldPort);
- END;
- END;
-
- {---------------------------------------------------}
- {$IFC qDebug}
- {$S AFields}
-
- PROCEDURE TPlotDoc.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- VAR
- aStr : DecStr;
- form : DecForm;
- aReal: Real;
-
- BEGIN
-
- form.style := FloatDecimal;
- form.digits := 6;
-
- DoToField('TPlotDoc', NIL, bClass);
- aReal := faParam;
- Num2Str(form,aReal,aStr);
- DoToField('faParam', @aStr, bString);
-
- aReal := fbParam;
- Num2Str(form,aReal,aStr);
- DoToField('fbParam', @aStr, bString);
-
- aReal := fcParam;
- Num2Str(form,aReal,aStr);
- DoToField('fcParam', @aStr, bString);
-
- aReal := fstepParam;
- Num2Str(form,aReal,aStr);
- DoToField('fstepParam', @aStr, bString);
- DoToField('fxParam', @fxParam, bInteger);
- DoToField('fyParam', @fyParam, bInteger);
-
- DoToField(' Font', @fPlotSpecs.theTextFont, bFontName);
- DoToField(' Face', @fPlotSpecs.theTextFace, bStyle);
- DoToField(' Size', @fPlotSpecs.theTextSize, bInteger);
-
- INHERITED Fields(DoToField);
- END;
- {$ENDC}
-
-
- {******************************************************************************************}
- { T P l o t D i a l o g }
- {******************************************************************************************}
- {$S }
-
- PROCEDURE TPlotDialog.DismissDialog(dismisser: IDType; flashDismisser: BOOLEAN); OVERRIDE;
-
- BEGIN
- INHERITED DismissDialog(dismisser, flashDismisser);
- END;
-
-
- {---------------------------------------------------}
- FUNCTION TPlotDialog.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
- VAR info: EventInfo): TCommand; OVERRIDE;
- BEGIN
- { If Enter is pressed, assume we have new parameters
- and a new plot to create. }
- IF (ch = chEnter) THEN
- BEGIN
- PlotNDrawPICT; { we have everything, lets DOIT! }
- DoKeyCommand := gNoChanges; { We did all the work no reason to
- generate a command}
- END
- ELSE
- DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
- END;
-
-
- {---------------------------------------------------}
- FUNCTION TPlotDialog.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
-
- BEGIN
- { Plot Menu Command was chosen so create the plot. }
- IF (aCmdNumber = cPlotIt) THEN
- BEGIN
- PlotNDrawPICT; { we have everything, lets DOIT! }
- DoMenuCommand := gNoChanges; { We did all the work no reason to
- generate a command}
- END
- ELSE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END;
-
-
- {---------------------------------------------------}
- PROCEDURE TPlotDialog.DoSetupMenus; OVERRIDE;
-
- BEGIN
- Enable(cPlotIt, TRUE);
- INHERITED DoSetupMenus;
- END;
-
-
- {---------------------------------------------------}
- PROCEDURE TPlotDialog.Draw(area: Rect); OVERRIDE;
- VAR
- plotRect : Rect;
- dontCare : BOOLEAN;
-
- BEGIN
- { dontCare := SELF.Focus; }
- dontCare := fPlotView.Focus;
- { set the world up to focus all drawing in the PlotView }
-
- fPlotView.GetQDFrame(plotRect);
- { the design says we draw into the available frame }
-
- DrawPicture(fPlotPICT, plotRect);
- { Draw the PICT in the PlotView }
-
- dontCare := SELF.Focus;
- { shift the focus back to us }
-
- END;
-
-
- {---------------------------------------------------}
- PROCEDURE TPlotDialog.EachSubView(PROCEDURE DoToSubView(theSubView: TView));
- BEGIN
- { We do not want all of our clever dialog elements printing so lets
- skip them when printing }
- IF NOT gPrinting THEN
- INHERITED EachSubView(DoToSubView);
- END;
-
- {---------------------------------------------------}
- PROCEDURE TPlotDialog.PlotNDrawPICT;
- VAR
- plotRect : Rect;
- solveRect : Rect;
- saveClip : RgnHandle;
- pstate : PenState;
- dontCare : BOOLEAN;
- aFontNum : INTEGER;
-
- BEGIN
-
- GetPlotValues;
- { get current values from the view }
- fPlotDoc.SolveQuadratic;
- { for the parameters retrieved, setup the solution values }
-
-
- IF fPlotPICT <> NIL THEN
- KillPicture(fPlotPICT);
-
- dontCare := fPlotView.Focus;
- fPlotView.GetQDExtent(plotRect);
- { change MacApp’s focus to the plotview
- to properly get our plot rect}
- dontCare := SELF.Focus;
- { and of course lets set the FOCUS back to us.
- The above process of setting up plotRect might have
- been better handleed by declaring an fRect in plotview
- and having the resize method of plotview keep it up to date}
-
- fPlotPICT := OpenPicture(plotRect);
-
- saveClip := NewRgn;
- FailNIL(SaveClip);
- GetClip(SaveClip);
-
- GetPenState(pstate);
-
- { setup the font info for our plot }
- {$Push} {$H-}
- GetFNum(fPlotDoc.fPlotSpecs.theTextFont, aFontNum);
- {$H+}
- TextFont(aFontNum);
- TextSize(fPlotDoc.fPlotSpecs.theTextSize);
- TextFace(fPlotDoc.fPlotSpecs.theTextFace);
- { we also have: theTextColor, theJustification, theBackColor
- that we might want to do something with in the future }
- TextMode(srcOr);
-
- {Begin MacDraw Document PICT}
- PicComment(picDwgBeg, 0, NIL);
- PicComment(picGrpBeg, 0, NIL);
-
- fPlotView.AddToPict(plotRect);
-
- solveRect := fSolutionView.fSolveRect;
- { get our plot rect, we know that this is a fixed rect}
-
- offsetRect(solveRect,4{border},plotRect.Bottom-(solveRect.Bottom+4{border}));
- { slide the textbox on down to the bottom of the view area
- this assumes that the solution textbox is smaller than the plotRect}
-
- fSolutionView.AddToPict(solveRect);
-
- PicComment(PicGrpEnd, 0, NIL);
- PicComment(picDwgEnd, 0, NIL);
-
- ClosePicture;
-
- SetPenState(pstate);
- SetClip(saveClip);
-
- DisposeRgn(saveClip);
-
- ForceRedraw;
- { make the dialog rect invalid }
- END;
-
- {---------------------------------------------------}
- PROCEDURE TPlotDialog.GetPlotValues;
-
- BEGIN
-
- fPlotDoc.faParam := TExtendedText(FindSubView('cofA')).GetValue;
- fPlotDoc.fbParam := TExtendedText(FindSubView('cofB')).GetValue;
- fPlotDoc.fcParam := TExtendedText(FindSubView('cofC')).GetValue;
-
- fPlotDoc.fstepParam := TExtendedText(FindSubView('step')).GetValue;
- fPlotDoc.fxParam := TNumberText(FindSubView('xAxs')).GetValue;
- fPlotDoc.fyParam := TNumberText(FindSubView('yAxs')).GetValue;
-
- END;
-
- {---------------------------------------------------}
- PROCEDURE TPlotView.GetQDFrame(VAR frameRect:Rect);
- VAR
- extent: VRect;
-
- BEGIN
- GetFrame(extent);
- ViewToQDRect(extent, frameRect);
- END;
-
- {---------------------------------------------------}
- PROCEDURE TPlotView.AddToPict(picRect:Rect);
- CONST
- AxisLabelIndent = 4;
-
- TYPE
- Widpt = Point;
- WidPtr = ^WidPt;
- WidHdl = ^WidPtr;
-
- VAR
- x, y : Real;
- a,b,c : Real;
- step : Real;
- halfXScale : Real;
- xPictScale : Real;
- yPictScale : Real;
-
- lastPt : Point;
- thisPt : Point;
- xScale : INTEGER;
- yScale : INTEGER;
- CenterHorz : INTEGER;
- CenterVert : INTEGER;
- PictHorz : INTEGER;
- PictVert : INTEGER;
-
- leading : INTEGER;
- fInfo : FontInfo;
- Width : Widhdl;
- axisLabel : str255;
-
- newColor : RGBColor;
- oldBack : RGBColor;
- oldFore : RGBColor;
-
- drawLine : BOOLEAN;
-
- BEGIN
-
- Width := Widhdl(NewHandle(sizeof(widpt)));
- Width^^.h := 10;
- Width^^.v := 1;
-
- GetFontInfo(fInfo);
- leading := fInfo.descent + fInfo.ascent + fInfo.leading;
-
- WITH fPlotDoc DO
- BEGIN
- { retrieve the length of our Axis }
- xScale := fxParam;
- yScale := fyParam;
-
- { retrieve the coeficients }
- a := faParam;
- b := fbParam;
- c := fcParam;
- step := fStepParam;
- END;
-
- ClipRect(picRect);
-
- GetForeColor(oldFore);
- GetBackColor(oldBack);
-
- PenNormal;
-
-
- {Draw Graph Boundry}
- PicComment(picGrpBeg, 0, NIL);
-
- newColor := fPlotDoc.fPlotSpecs.theBackColor;
- RGBBackColor(newColor);
-
- PicComment(SetLineWidth, GetHandleSize(Handle(Width)), Handle(Width));
- FillRect(picRect, white);
- FrameRect(picRect);
-
-
- {Two Axis}
- newColor := fPlotDoc.fPlotSpecs.theAxisColor;
- RGBForeColor(newColor);
-
- { find the height of our View that we will draw into }
- PictHorz := picRect.right - picRect.left;
- PictVert := picRect.bottom - picRect.top;
-
- { find the center coordinates of the view }
- CenterHorz := PictHorz DIV 2;
- CenterVert := PictVert DIV 2;
-
- PicComment(picGrpBeg, 0, NIL);
- moveto(0, CenterVert);
- line( PictHorz, 0);
- moveto(CenterHorz, 0);
- line(0, PictVert);
- PicComment(picGrpEnd, 0, NIL);
-
-
- newColor := fPlotDoc.fPlotSpecs.theGraphColor;
- RGBForeColor(newColor);
-
- {Axis Text}
- { Place -X axis label to the lowerleft of the axis line }
- moveto(AxisLabelIndent, CenterVert + leading);
- NumToString(-xScale,axisLabel);
- DrawString(axisLabel);
-
- { Place +Y axis label to the topleft of the axis line }
- NumToString(yScale,axisLabel);
- moveto(CenterHorz - (StringWidth(axisLabel) + AxisLabelIndent), leading);
- DrawString(axisLabel);
-
- { Place +X axis label to the lowerright of the axis line }
- NumToString(xScale,axisLabel);
- moveto(PictHorz - (StringWidth(axisLabel) + AxisLabelIndent),
- CenterVert + leading);
- DrawString(axisLabel);
-
- { Place -Y axis label to the lowerleft of the axis line }
- NumToString(-yScale,axisLabel);
- moveto(CenterHorz - (StringWidth(axisLabel) + AxisLabelIndent),
- PictVert - leading);
- DrawString(axisLabel);
-
- {The Plot}
- { calculate a scale factor for the PICT’s axis in the view }
- xPictScale := PictHorz / xScale;
- yPictScale := PictVert / yScale;
-
-
- { calculate our starting x,y point }
- halfXScale := xScale / 2;
- x := -halfXScale;
- y := a * x * x + (b * x) + c;
-
- { Scale it into the PICT’s (and PostScript’s) view space}
- thisPt.h := integer(round(x * xPictScale))+CenterHorz;
- thisPt.v := integer(round(-y * yPictScale))+CenterVert;
-
- { The original did not clip lines so here is a feeble stab at
- find wher to stop and start drawing.
- LOOP until we reach all x values:
- 1. Find our first visible line segment
- 2. Plot until it disappears
- 3. Find a suitable end point
- }
-
- WHILE (NOT PtInRect(thisPt,picRect)) & (x <= halfXscale) DO
- BEGIN
- x := x + step;
- y := a * x * x + (b * x) + c;
- thisPt.h := integer(round(x * xPictScale))+CenterHorz;
- thisPt.v := integer(round(-y * yPictScale))+CenterVert;
- END;
-
- moveTo(thisPt.h,thisPt.v);
- drawLine := TRUE;
-
- PicComment(picGrpBeg, 0, NIL);
-
- REPEAT
- x := x + step;
- y := (a * x * x) + (b * x) + c;
- thisPt.h := integer(round(x * xPictScale))+CenterHorz;
- thisPt.v := integer(round(-y * yPictScale))+CenterVert;
- IF NOT PtInRect(thisPt,picRect) THEN
- drawLine := FALSE
- ELSE
- BEGIN
- IF drawLine THEN
- LineTo(thisPt.h,thisPt.v)
- ELSE
- BEGIN
- drawLine := TRUE;
- moveTo(thisPt.h,thisPt.v)
- END
- END;
-
- writeln('h:',thisPt.h,' v:',thisPt.v);
-
- UNTIL x >= halfXScale;
-
- PicComment(picGrpEnd, 0, NIL);
-
- RGBForeColor(oldFore);
- RGBBackColor(oldBack);
-
- PicComment(PicGrpEnd, 0, NIL); {of select all objects}
-
- END;
-
- {---------------------------------------------------}
-
- PROCEDURE TPlotView.Resize(width, height: VCoordinate; invalidate: BOOLEAN); OVERRIDE;
- BEGIN
- invalidate := TRUE;
- INHERITED Resize(width, height, invalidate);
- ForceRedraw;
- END;
-
-
- {---------------------------------------------------}
- { Adds the text box containing the Quadratic equation solution to our PICT. }
-
- PROCEDURE TSolutionView.AddToPict(picRect: Rect);
-
- CONST
- k1stLine = 1; k2ndLine = 2; k3rdLine = 3;
- k4thLine = 4; k5thLine = 5;
-
- kLeftJust = 1;
- kIndent = 2;
-
- TYPE
- Widpt = Point;
- WidPtr = ^WidPt;
- WidHdl = ^WidPtr;
-
- TTxtPicRec = PACKED RECORD
- tJus : Byte;
- tFlip : Byte;
- tRot : Integer;
- tLine : Byte;
- tCmnt : Byte;
- END;
-
- VAR
- TextClipRgn : RgnHandle;
- TxtPicRec : TTxtPicRec;
- TxtPicPtr : QDPtr;
- TxtPicHdl : QDHandle;
- Width : WidHdl;
-
- clipBox : Rect;
- boxTop : INTEGER;
- boxLeft : INTEGER;
- leading : INTEGER;
- fInfo : FontInfo;
- LineNo : INTEGER;
-
- a,b,c : Real;
- x1,x2 : Real;
- z1,z2 : Real;
-
- newColor : RGBColor;
-
- BEGIN
-
- WITH fPlotDoc DO
- BEGIN
- { retrieve the Solution }
- x1 := f1stRoot;
- x2 := f2ndRoot;
-
- { retrieve the coeficients }
- a := faParam;
- b := fbParam;
- c := fcParam;
- END;
-
- Width := Widhdl(NewHandle(sizeof(widpt)));
- Width^^.h := 10;
- Width^^.v := 1;
-
- GetFontInfo(fInfo);
- leading := fInfo.descent + fInfo.ascent + fInfo.leading;
-
- PicComment(picGrpBeg, 0, NIL);
-
- {Box }
- PicComment(picGrpBeg, 0, NIL);
- PicComment(SetLineWidth, GetHandleSize(Handle(Width)), Handle(Width));
- fillRect(picRect, white);
- frameRect(picRect);
- PicComment(picGrpEnd, 0, NIL); {of box}
-
- TextClipRgn := NewRgn;
- FailNil(TextClipRgn);
-
- GetClip(TextClipRgn);
- clipBox := picRect;
- ClipRect(clipBox);
-
- newColor := fPlotDoc.fPlotSpecs.theTextColor;
- RGBForeColor(newColor);
-
- {Box Text}
- { setup our Text Comment Handle }
- TxtPicPtr := @TxtPicRec;
- TxtPicHdl := @TxtPicPtr;
- TxtPicRec.tJus := kLeftJust;
- TxtPicRec.tFlip := 0; {no flip}
- TxtPicRec.tRot := 0; {no rotation}
- TxtPicRec.tLine := 2; {1 1/2 spacing}
-
- {put the Comment into our PICT}
- PicComment(TextBegin, sizeof(TTxtPicRec), Handle(TxtPicHdl));
-
- { Add the BOX text to the PICT }
- boxTop := picRect.top;
- boxLeft:= picRect.Left;
-
- MoveTo(boxLeft + kIndent, boxTop + (k1stLine * leading));
- DrawString(CONCAT('y=ax^2 + bx + c', chr(13)));
-
- MoveTo(boxLeft + kIndent, boxTop + (k2ndLine * leading));
- DrawString(CONCAT( 'a=', Real2Str(a,1),
- ', b=', Real2Str(b,1),
- ', c=', Real2Str(c,1), chr(13)));
-
- { The solution text is next }
- MoveTo(boxLeft + kIndent, boxTop + (k3rdLine * leading));
- DrawString(CONCAT( 'x1=', Real2Str(x1,3),
- ', x2=', Real2Str(x2,3), chr(13)));
-
- { Display the kind of Quadratic soultion we have }
- MoveTo(boxLeft + kIndent, boxTop + (k4thLine * leading));
- CASE fPlotDoc.fRootType OF
- RealRoots :
- DrawString(CONCAT('Two Real Roots, x1, x2', chr(13)));
- SingleSolution :
- DrawString(CONCAT('Double Root', chr(13)));
- ComplexRoot :
- DrawString(CONCAT('Two Complex Roots ', chr(13)));
- OTHERWISE
- ;
- END;
-
- { Calculate the slope and add the string it to the PICT}
- WITH fPlotDoc DO
- BEGIN
- z1 := -b / (2 * a);
- z2 := (4 * a * c - (b * b)) / (4 * b);
- END;
-
- MoveTo(boxLeft + kIndent, boxTop + (k5thLine * leading));
- DrawString(CONCAT('Slope 0 is (', Real2Str(z1,1),
- ',', Real2Str(z2,1),')', chr(13)));
-
- { All done with our text }
- PicComment(TextEnd, 0, NIL);
-
- PicComment(PicGrpEnd, 0, NIL); {of Box & text}
-
- DisposHandle(Handle(width));
- DisposeRgn(TextClipRgn);
-
- END;
-
-
-
- {---------------------------------------------------}
- PROCEDURE TPStyleCmd.DoIt;
- BEGIN
- fPlotDialog.fPlotDoc.fPlotSpecs := fNewPlotSPecs;
- END;
-
-
- {---------------------------------------------------}
- PROCEDURE TPStyleCmd.ReDoIt;
- BEGIN
- fPlotDialog.fPlotDoc.fPlotSpecs := fNewPlotSPecs;
- END;
-
-
- {---------------------------------------------------}
- PROCEDURE TPStyleCmd.UnDoIt;
- BEGIN
- fPlotDialog.fPlotDoc.fPlotSpecs := fOldPlotSPecs;
- END;
-
-
- {---------------------------------------------------}
- PROCEDURE TPStyleCmd.IPStyleCmd(itsPlotDialog: TPlotDialog;itsNewStyle: PlotSpecsPtr;itsCmdNumber: CmdNumber);
-
- BEGIN
- ICommand(itsCmdNumber, itsPlotDialog.fPlotDoc, itsPlotDialog, NIL);
-
- fPlotDialog := itsPlotDialog;
- fOldPlotSPecs := fPlotDialog.fPlotDoc.fPlotSpecs;
- fNewPlotSPecs := itsNewStyle^;
- END;
-
- END.
-
- (*
- {---------------------------------------------------}
- { T H E M A I N P R O G R A M }
-
- BEGIN
-
- InitUMacApp(8); {Initialize the Toolbox, making 8 calls to
- MoreMasters:}
- InitPrinting; {Initialize the UPrinting unit:}
-
- NEW(gPlotApplication); {Allocate a new TPlotApplication object:}
- FailNIL(gPlotApplication);
- gPlotApplication.IPlotApplication(kFileType); {Initialize that new object:}
-
- gPlotApplication.Run; {Run the application. When it's done, exit.}
- END.
- *)